package luafrontend.values;

import luafrontend.exceptions.ConversionException;

public abstract class LuaValue {
	private LuaTable metatable;
	
	public void setMetatable(LuaTable table) {
		metatable = table;
	}
	
	public LuaTable getMetatable() {
		return metatable;
	}
	
	public LuaNumber asNumber() throws ConversionException {
		throw new ConversionException("Unable to convert " + toString() + " to number");
	}
	
	public LuaString asString() throws ConversionException {
		throw new ConversionException("Unable to convert " + toString() + " to string");
	}
	
	public LuaFunction asFunction() throws ConversionException {
		throw new ConversionException("Unable to convert " + toString() + " to function");
	}
	
	public LuaTable asTable() throws ConversionException {
		throw new ConversionException("Unable to convert " + toString() + " to table");
	}
	
	public LuaBool asBool() throws ConversionException {
		return new LuaBool(!isNil());
	}
	
	public boolean isNil() {
		return false;
	}
	
	public abstract String toString();
}
